local base = class("base")
local id = 0
function base:init(...)
end

function base:createData(...)    
    self.data = {...}
end

function base:getData()
    self.data.id = self.id
    self.data.tag = self.tag
    self.data.netID = self.netID
    if self.bornTimer then
        self.data[7] = self.bornTimer
    end
    return self.data
end

function base:setID(id)
    self.id = tostring(id)
    self.game.objects[self.id] = self
end

function base:syncMove()
    local data = {
            id = self.id,
            x = self.x,
            y = self.y,
            rot = self.rot
        }
    if net.inGame then
        net.client:send("need_move",data)
    elseif net.server and self.dirty then
        self.dirty = false
        net:sendToRoom(self.game.room,"move_obj",data)
    end
end

function base:destroy()
    self.destroyed = true
    if self.aabb then
        if self.game.world:hasItem(self) then
            self.game.world:remove(self)
        end
    end
    if self.game.objects[self.id] then
        self.game.objects[self.id]  = nil
    end
    if net.server then
        net:sendToRoom(self.game.room,"kill_obj",{id = self.id})
    end
end

return base